# coding:utf-8
__author__ = 'cgk'


class Singleton(object):
    '''
    将一个类的实例绑定到类变量_instance上,
    如果cls._instance为None说明该类还没有实例化过,实例化该类,并返回
    如果cls._instance不为None,直接返回cls._instance
    '''
    def __new__(cls, *args, **kw):
        if not hasattr(cls, '_instance'):
            orig = super(Singleton, cls)
            cls._instance = orig.__new__(cls, *args, **kw)
        return cls._instance


if __name__ == '__main__':
    import datetime
    # new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
    sdf = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    print sdf